/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import vn.com.fis.portal.model.UserServiceEntry;
import vn.com.fis.portal.model.UserServiceEntryModel;
import vn.com.fis.portal.model.UserServiceEntrySoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the UserServiceEntry service. Represents a row in the &quot;TBL_USER_SERVICE&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link vn.com.fis.portal.model.UserServiceEntryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link UserServiceEntryImpl}.
 * </p>
 *
 * @author loind
 * @see UserServiceEntryImpl
 * @see vn.com.fis.portal.model.UserServiceEntry
 * @see vn.com.fis.portal.model.UserServiceEntryModel
 * @generated
 */
@JSON(strict = true)
public class UserServiceEntryModelImpl extends BaseModelImpl<UserServiceEntry>
	implements UserServiceEntryModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a user service entry model instance should use the {@link vn.com.fis.portal.model.UserServiceEntry} interface instead.
	 */
	public static final String TABLE_NAME = "TBL_USER_SERVICE";
	public static final Object[][] TABLE_COLUMNS = {
			{ "userServiceId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "serviceId", Types.BIGINT },
			{ "serviceStatus", Types.INTEGER },
			{ "serviceStartDate", Types.TIMESTAMP },
			{ "serviceStopDate", Types.TIMESTAMP },
			{ "servicePackageId", Types.BIGINT },
			{ "packageDate", Types.TIMESTAMP }
		};
	public static final String TABLE_SQL_CREATE = "create table TBL_USER_SERVICE (userServiceId LONG not null primary key,userId LONG,serviceId LONG,serviceStatus INTEGER,serviceStartDate DATE null,serviceStopDate DATE null,servicePackageId LONG,packageDate DATE null)";
	public static final String TABLE_SQL_DROP = "drop table TBL_USER_SERVICE";
	public static final String ORDER_BY_JPQL = " ORDER BY userServiceEntry.serviceId ASC";
	public static final String ORDER_BY_SQL = " ORDER BY TBL_USER_SERVICE.serviceId ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.vn.com.fis.portal.model.UserServiceEntry"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.vn.com.fis.portal.model.UserServiceEntry"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.vn.com.fis.portal.model.UserServiceEntry"),
			true);
	public static long SERVICEID_COLUMN_BITMASK = 1L;
	public static long SERVICEPACKAGEID_COLUMN_BITMASK = 2L;
	public static long USERID_COLUMN_BITMASK = 4L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static UserServiceEntry toModel(UserServiceEntrySoap soapModel) {
		UserServiceEntry model = new UserServiceEntryImpl();

		model.setUserServiceId(soapModel.getUserServiceId());
		model.setUserId(soapModel.getUserId());
		model.setServiceId(soapModel.getServiceId());
		model.setServiceStatus(soapModel.getServiceStatus());
		model.setServiceStartDate(soapModel.getServiceStartDate());
		model.setServiceStopDate(soapModel.getServiceStopDate());
		model.setServicePackageId(soapModel.getServicePackageId());
		model.setPackageDate(soapModel.getPackageDate());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<UserServiceEntry> toModels(
		UserServiceEntrySoap[] soapModels) {
		List<UserServiceEntry> models = new ArrayList<UserServiceEntry>(soapModels.length);

		for (UserServiceEntrySoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.vn.com.fis.portal.model.UserServiceEntry"));

	public UserServiceEntryModelImpl() {
	}

	public long getPrimaryKey() {
		return _userServiceId;
	}

	public void setPrimaryKey(long primaryKey) {
		setUserServiceId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_userServiceId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return UserServiceEntry.class;
	}

	public String getModelClassName() {
		return UserServiceEntry.class.getName();
	}

	@JSON
	public long getUserServiceId() {
		return _userServiceId;
	}

	public void setUserServiceId(long userServiceId) {
		_userServiceId = userServiceId;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	@JSON
	public long getServiceId() {
		return _serviceId;
	}

	public void setServiceId(long serviceId) {
		_columnBitmask = -1L;

		if (!_setOriginalServiceId) {
			_setOriginalServiceId = true;

			_originalServiceId = _serviceId;
		}

		_serviceId = serviceId;
	}

	public long getOriginalServiceId() {
		return _originalServiceId;
	}

	@JSON
	public int getServiceStatus() {
		return _serviceStatus;
	}

	public void setServiceStatus(int serviceStatus) {
		_serviceStatus = serviceStatus;
	}

	@JSON
	public Date getServiceStartDate() {
		return _serviceStartDate;
	}

	public void setServiceStartDate(Date serviceStartDate) {
		_serviceStartDate = serviceStartDate;
	}

	@JSON
	public Date getServiceStopDate() {
		return _serviceStopDate;
	}

	public void setServiceStopDate(Date serviceStopDate) {
		_serviceStopDate = serviceStopDate;
	}

	@JSON
	public long getServicePackageId() {
		return _servicePackageId;
	}

	public void setServicePackageId(long servicePackageId) {
		_columnBitmask |= SERVICEPACKAGEID_COLUMN_BITMASK;

		if (!_setOriginalServicePackageId) {
			_setOriginalServicePackageId = true;

			_originalServicePackageId = _servicePackageId;
		}

		_servicePackageId = servicePackageId;
	}

	public long getOriginalServicePackageId() {
		return _originalServicePackageId;
	}

	@JSON
	public Date getPackageDate() {
		return _packageDate;
	}

	public void setPackageDate(Date packageDate) {
		_packageDate = packageDate;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public UserServiceEntry toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (UserServiceEntry)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					UserServiceEntry.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		UserServiceEntryImpl userServiceEntryImpl = new UserServiceEntryImpl();

		userServiceEntryImpl.setUserServiceId(getUserServiceId());
		userServiceEntryImpl.setUserId(getUserId());
		userServiceEntryImpl.setServiceId(getServiceId());
		userServiceEntryImpl.setServiceStatus(getServiceStatus());
		userServiceEntryImpl.setServiceStartDate(getServiceStartDate());
		userServiceEntryImpl.setServiceStopDate(getServiceStopDate());
		userServiceEntryImpl.setServicePackageId(getServicePackageId());
		userServiceEntryImpl.setPackageDate(getPackageDate());

		userServiceEntryImpl.resetOriginalValues();

		return userServiceEntryImpl;
	}

	public int compareTo(UserServiceEntry userServiceEntry) {
		int value = 0;

		if (getServiceId() < userServiceEntry.getServiceId()) {
			value = -1;
		}
		else if (getServiceId() > userServiceEntry.getServiceId()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		UserServiceEntry userServiceEntry = null;

		try {
			userServiceEntry = (UserServiceEntry)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = userServiceEntry.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		UserServiceEntryModelImpl userServiceEntryModelImpl = this;

		userServiceEntryModelImpl._originalUserId = userServiceEntryModelImpl._userId;

		userServiceEntryModelImpl._setOriginalUserId = false;

		userServiceEntryModelImpl._originalServiceId = userServiceEntryModelImpl._serviceId;

		userServiceEntryModelImpl._setOriginalServiceId = false;

		userServiceEntryModelImpl._originalServicePackageId = userServiceEntryModelImpl._servicePackageId;

		userServiceEntryModelImpl._setOriginalServicePackageId = false;

		userServiceEntryModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<UserServiceEntry> toCacheModel() {
		UserServiceEntryCacheModel userServiceEntryCacheModel = new UserServiceEntryCacheModel();

		userServiceEntryCacheModel.userServiceId = getUserServiceId();

		userServiceEntryCacheModel.userId = getUserId();

		userServiceEntryCacheModel.serviceId = getServiceId();

		userServiceEntryCacheModel.serviceStatus = getServiceStatus();

		Date serviceStartDate = getServiceStartDate();

		if (serviceStartDate != null) {
			userServiceEntryCacheModel.serviceStartDate = serviceStartDate.getTime();
		}
		else {
			userServiceEntryCacheModel.serviceStartDate = Long.MIN_VALUE;
		}

		Date serviceStopDate = getServiceStopDate();

		if (serviceStopDate != null) {
			userServiceEntryCacheModel.serviceStopDate = serviceStopDate.getTime();
		}
		else {
			userServiceEntryCacheModel.serviceStopDate = Long.MIN_VALUE;
		}

		userServiceEntryCacheModel.servicePackageId = getServicePackageId();

		Date packageDate = getPackageDate();

		if (packageDate != null) {
			userServiceEntryCacheModel.packageDate = packageDate.getTime();
		}
		else {
			userServiceEntryCacheModel.packageDate = Long.MIN_VALUE;
		}

		return userServiceEntryCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(17);

		sb.append("{userServiceId=");
		sb.append(getUserServiceId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", serviceId=");
		sb.append(getServiceId());
		sb.append(", serviceStatus=");
		sb.append(getServiceStatus());
		sb.append(", serviceStartDate=");
		sb.append(getServiceStartDate());
		sb.append(", serviceStopDate=");
		sb.append(getServiceStopDate());
		sb.append(", servicePackageId=");
		sb.append(getServicePackageId());
		sb.append(", packageDate=");
		sb.append(getPackageDate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(28);

		sb.append("<model><model-name>");
		sb.append("vn.com.fis.portal.model.UserServiceEntry");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>userServiceId</column-name><column-value><![CDATA[");
		sb.append(getUserServiceId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>serviceId</column-name><column-value><![CDATA[");
		sb.append(getServiceId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>serviceStatus</column-name><column-value><![CDATA[");
		sb.append(getServiceStatus());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>serviceStartDate</column-name><column-value><![CDATA[");
		sb.append(getServiceStartDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>serviceStopDate</column-name><column-value><![CDATA[");
		sb.append(getServiceStopDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>servicePackageId</column-name><column-value><![CDATA[");
		sb.append(getServicePackageId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>packageDate</column-name><column-value><![CDATA[");
		sb.append(getPackageDate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = UserServiceEntry.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			UserServiceEntry.class
		};
	private long _userServiceId;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private long _serviceId;
	private long _originalServiceId;
	private boolean _setOriginalServiceId;
	private int _serviceStatus;
	private Date _serviceStartDate;
	private Date _serviceStopDate;
	private long _servicePackageId;
	private long _originalServicePackageId;
	private boolean _setOriginalServicePackageId;
	private Date _packageDate;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private UserServiceEntry _escapedModelProxy;
}